<template>
	<view class="favorite-list-page">
		<!-- 收藏列表 -->
		<view v-for="(item, index) in list" :key="index" class="favorite-item" @click="viewTopicDetail(item.topic)">
			<!-- 左侧图片 -->
			<view class="left-image">
				<image :src="hname+item.mediaUrl" class="item-image" mode="aspectFill"></image>
			</view>
			<!-- 右侧标题和内容 -->
			<view class="right-content">
				<text class="item-title">{{ item.title }}</text>
				<text class="item-content">{{ item.content }}</text>
			</view>
		</view>
	</view>
</template>

<script>
	import {
		baseUrl,
		getTopicList
	} from "@/api/index.js"
	export default {
		data() {
			return {
				hname: baseUrl,
				userInfo: {},
				list: []
			};
		},
		async onLoad() {
			let uInfo = uni.getStorageSync('mini-userinfo')
			if (uInfo) {
				this.userInfo = uInfo
			}
			const res = await getTopicList({userId:this.userInfo.id})
			this.list = res.data.data
			console.log(res, '????????????');
		},
		methods: {
			viewTopicDetail(topic) {
				// const params = encodeURIComponent(JSON.stringify(topic));
				uni.navigateTo({
					url: `/pages/community/detail?topicId=${topic.id}`
				})
			},
		}
	};
</script>

<style lang="scss" scoped>
	.favorite-list-page {
		padding: 20rpx;
	}

	.favorite-item {
		display: flex;
		margin-bottom: 30rpx;
		padding: 20rpx;
		border-bottom: 1rpx solid #eee;
	}

	.left-image {
		width: 200rpx;
		height: 200rpx;
		margin-right: 40rpx;
	}

	.item-image {
		width: 100%;
		height: 100%;
		border-radius: 8rpx;
	}

	.right-content {
		flex: 1;
		display: flex;
		flex-direction: column;
		justify-content: center;
	}

	.item-title {
		font-size: 32rpx;
		color: #333;
		margin-bottom: 10rpx;
		overflow: hidden;
		text-overflow: ellipsis;
		display: -webkit-box;
		-webkit-box-orient: vertical;
		-webkit-line-clamp: 1;
	}

	.item-content {
		font-size: 28rpx;
		color: #666;
		overflow: hidden;
		text-overflow: ellipsis;
		display: -webkit-box;
		-webkit-box-orient: vertical;
		-webkit-line-clamp: 2;
	}
</style>